<?php
/**
*   会员等级
*/
namespace app\api\model;
use think\Model;

class MemberLevel extends Model
{
    /**
    *   常见问题列表
    */
    public function _list($where = 'status = 1', $order_by="sort asc", $page_size = PAGE_SIZE_API){
        $obj = $this->order($order_by);
        $data = $this->where($where)
            ->field('id,title, image, balance, gold')
            ->order($order_by)
            ->select()
            ->toArray();
        return $data;
    }
    
    /**
    * 通过id获取内容
    * @param id int 等级id
    * @return array|false 
    */
    public function _getById($id){
        $data = $this->field('id,title, image, balance, gold')->where([['id', '=', $id], ['status', '=', 1]])->find();
        if(empty($data)){
            $this->error = '该等级不存在';
            return false;
        }
        
        
        return $data;
    }
    
    /**
    * 获取下一级信息
    * @param id int 等级id 
    */
    public function _getNextLevel($id){
        $data = $this->field('id,title, image, balance, gold, sort')->where([['id', '=', $id], ['status', '=', 1]])->find();
        
        $next = $this->field('id,title, image, balance, gold, sort')->where([['status', '=', 1], ['sort', '>', $data['sort']]])->order("sort asc")->find();
        return $next;
    }

}